<template>
  <div class="gender">
    <div class="title">
      <p>男女比例</p>
      <img src="../../images/dataScreen-title.png" alt="">
    </div>
    <!-- 男女头像 -->
    <div class="gender1">
      <div class="man">
        <img src="../../images/man.png" alt="">
      </div>
      <div class="woman">
        <img src="../../images/woman.png" alt="">
      </div>
    </div>

    <!-- 男女比率文字 -->
    <div class="rate">
      <p>男性58%</p>
      <p>女性42%</p>
    </div>

    <!-- 男女比例柱状图 -->
    <div class="charts" ref="charts">

    </div>

  </div>
</template>
<script setup lang='ts'>
import { ref, onMounted } from 'vue'
import * as echarts from 'echarts'
// 获取图形图表节点
let charts = ref()

onMounted(() => {
  // 获取echarts类的实例
  let mychart = echarts.init(charts.value)
  // 设置实例的配置项
  mychart.setOption({
    // 标题
    title: {
      text: '男女比例',
      textStyle: {
        color: 'skyblue'
      },
      left: '40%',
    },
    xAxis: {
      show: false, // 是否展示x轴本身的轴图标
      min: 0,
      max: 100
    },
    yAxis: {
      show: false,
      type: 'category'
    },
    // 图表展示的样式：如线条、bar、饼图等
    series: [
      {
        type: 'bar',
        data: [58],
        barWidth: 20,
        itemStyle: {
          color: '#337ecc',
          borderRadius:20,
        },
        z: 100, 
      },
      {
        type: 'bar',
        data: [100],
        barWidth: 20, // 柱状宽度
        // 调整女士柱状条位置
        barGap: '-100%',
        // 调整女士柱状的颜色
        itemStyle: {
          color: '#f56c6c',
          borderRadius:20,
        },
        // 调整女士柱状层级
        z: 90,
      },
    ],
    // 图表布局
    grid: {
      left: 0,
      right: 0,
      top: 0,
      bottom: 0
    }
  })
})

</script>
<style scoped lang="scss">
.gender {
  width: 100%;
  height: 100%;
  background: url(../../images/dataScreen-main-cb.png) no-repeat;
  background-size: 100% 100%;
  margin: 20px 0px;

  .title {
    color: white;
    margin-left: 20px;
    font-size: 20px;
  }

  .gender1 {
    display: flex;
    justify-content: center;

    .man {
      margin: 20px;
      width: 111px;
      height: 115px;
      background: url(../../images/man-bg.png) no-repeat;
      // 👤位于盒子的水平和垂直居中
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .woman {
      margin: 20px;
      width: 111px;
      height: 115px;
      background: url(../../images/woman-bg.png);
      // 👤位于盒子的水平和垂直居中
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }

  .rate {
    display: flex;
    justify-content: space-between;
    color: white;
  }

  .charts {
    height: 100px;
  }

}
</style>